﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SuperSerialSamples.Timing;

namespace SuperSerialSamples
{
    class Program
    {
        static void Main(string[] args)
        {
            LiteralSamples.SerializeInteger();
            LiteralSamples.SerializeString();
            LiteralSamples.DeserializeInteger();
            LiteralSamples.DeserializeString();

            List<TimingResult> results = new List<TimingResult>();
            Console.WriteLine("TIMING:");
            results.Add(TimingSamples.DeserializeNamespace());
            results.Add(TimingSamples.DeserializeNoNamespace());
            DisplayResults(results);

            Console.ReadKey();
        }

        static void DisplayResults(List<TimingResult> results)
        {
            string totalMessage = "TOTAL";
            string millisecondHeader = "MS";
            string tickHeader = "TICKS";
            int maxLength = totalMessage.Length;
            int maxMSLength = millisecondHeader.Length;
            int maxTickLength = tickHeader.Length;
            long totalMilliseconds = 0;
            long totalTicks = 0;
            foreach(TimingResult result in results)
            {
                maxLength = Math.Max(result.Message.Length, maxLength);
                maxMSLength = Math.Max(result.Milliseconds.ToString().Length, maxMSLength);
                maxTickLength = Math.Max(result.Ticks.ToString().Length, maxTickLength);

                totalMilliseconds += result.Milliseconds;
                totalTicks += result.Ticks;
            }
            maxMSLength = Math.Max(totalMilliseconds.ToString().Length, maxMSLength);
            maxTickLength = Math.Max(totalTicks.ToString().Length, maxTickLength);

            Console.WriteLine("".PadLeft(maxLength) + "  " + millisecondHeader.PadLeft(maxMSLength) + " " + tickHeader.PadLeft(maxTickLength));

            foreach (TimingResult result in results)
            {
                Console.WriteLine(result.Message.PadLeft(maxLength) + ": " + result.Milliseconds.ToString().PadLeft(maxMSLength) + " " + result.Ticks.ToString().PadLeft(maxTickLength));
            }

            Console.WriteLine(totalMessage.PadLeft(maxLength) + ": " + totalMilliseconds.ToString().PadLeft(maxMSLength) + " " + totalTicks.ToString().PadLeft(maxTickLength));
        }
    }
}
